<?php
namespace app\admin\controller;
use think\Controller;
use think\Config;
use think\request;
use think\Db;

class Meeting extends Base
{
    /**
     * 会议主页
     * @Author   YGF
     * @DateTime 2018-06-29T19:21:18+0800
     */
 public function index(){

    return $this->fetch();
 }


   /**
     * 会议列表
     * @Author   YGF
     * @DateTime 2018-06-29T19:23:28+0800
     */
  public function listMeeting(Request $request){

   $page = $request->get('page');
        $limit = $request->get('limit');
        $start = ($page - 1) * $limit;
        $condition = $request->get('condition');
        if($condition){
            $where = " `name` LIKE '%$condition%'";
            $data=Db::name('meeting')->where($where)->limit($start,$limit)->select();
            $count=Db::name('meeting')->where($where)->count();
        } else {
            $data=Db::name('meeting')->limit($start,$limit)->select();
            $count=Db::name('meeting')->count();
        }
        dump($request->get('loading'));
        exit;
        return getTableJson(0,'success',$count,$data);     
 }

 /**
     * 新建会议
     * @Author   YGF
     * @DateTime 2018-06-29T19:24:10+0800
     */
     public function addMeeting(Request $request){

        if($request->isPost()){
            $data=$request->post();
            unset($data['file']);
            $res=Db::name('meeting')->insert($data);
              if($res){
                return getJson(0,'新增成功');
              }
                return getJson(1,'新增失败');
        }
        
    return $this->fetch();
 }

 /**
     * 编辑会议
     * @Author   YGF
     * @DateTime 2018-06-29T19:25:18+0800
     */
  public function editMeeting(Request $request){
 
        $id=input('id');
        $data=Db::name('meeting')
                ->where('id',$id)
                ->find();
        $this->assign('data',$data);

        if($request->isPost()){
            $data=$request->post();
            unset($data['file']);
              $res=Db::name('meeting')
                      ->where('id',$id)
                      ->update($data);
              if($res){
                return getJson(0,'修改成功');
              }
                return getJson(1,'数据没变更，无需提交');
        }
       return $this->fetch();
 }



 /**
     * 删除会议
     * @Author   YGF
     * @DateTime 2018-06-29T19:26:33+0800
     */
  public function delMeeting(Request $request){
        $id=input('id');
        $res=Db::name('meeting')->where('id',$id)->delete();
        if($res){
            return getJson(0,'删除成功');
        }
        return getJson(1,'删除失败');
 }  


    /**
     * 批量删除
     * @Author   YGF
     * @DateTime 2018-06-27T17:23:18+0800
     */
    public function batchDel (Request $request){
       $ids = $request->post('ids/a');
        $table = Config::get("database.prefix") . 'meeting';
        $res = Db::table($table)
                ->delete($ids);

        if($res){
            return getJson(0,'删除成功');
        }
        return getJson(1,'删除失败');
    }




 /**
     * 会议详情
     * @Author   YGF
     * @DateTime 2018-06-29T19:25:18+0800
     */
  public function showMeeting(Request $request){
 
        $id=input('id');
        $data=Db::name('meeting')
                ->where('id',$id)
                ->find();
        $this->assign('data',$data);
       return $this->fetch();
 }

}
